import os
import sys
import struct
import binascii

#with open('ux00_zsbl.dtb', 'rb') as f:
#    lines = f.readlines()
#    for l in lines:
#        print(l)
#    #header = f.read(4)
#    #print(header)
#    #print(header.decode('ascii'))
#    ##header2hex = struct.unpack('i', header)[0]
#    ##print(header2hex)
#    ##print(hex(header2hex))
#    print('\033[1;41m%s\033[0m' % ('=' * 20))
#    for l in lines:
#        print(str(l))

def read_bytes(f, x):
    '''read x bytes from f'''
    s = f.read(x)
    hexstr = binascii.b2a_hex(s)
    print(hexstr)
    return hexstr

with open('ux00_zsbl.dtb', 'rb') as f:
    magic = read_bytes(f, 4)
    totalsize = read_bytes(f, 4)
    off_dt_struct = read_bytes(f, 4)
    off_dt_string = read_bytes(f, 4)
    off_mem_rsvmap = read_bytes(f, 4)
    version = read_bytes(f, 4)

    print('magic=%s' % magic)
    if magic == b'd00dfeed': #big endian
        print('big endian')
    elif magic == b'edfe0dd0': #little endian
        print('little endian')
